package predatorpreysystems;
/*
 * Copyright (c) 2009 Project E7
 *
 * This file is part of PredatorPreySystems
 *
 * PredatorPreySystems is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * PredatorPreySystems is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PredatorPreySystems. If not, see <http://www.gnu.org/licenses/>.
 *
 * PredatorPreySystems is a project that demonstrates lotka volterra's predator
 * prey systems.  The project is also meant to demonstrate linear approximation
 * using differential equations and Euler's method.
 **/

import info.gridworld.actor.Actor;
import info.gridworld.actor.ActorWorld;
import info.gridworld.grid.BoundedGrid;
import info.gridworld.grid.Location;

/**
 *
 * @author markvismonte
 */
public class Main {

    private static PredatorPreySystemUtility ppsUtility;
    private static final int GRID_SIZE = 25;
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        ppsUtility = new PredatorPreySystemUtility(new BoundedGrid<Actor>(
                GRID_SIZE, GRID_SIZE));
        ppsUtility.reset();
        ActorWorld world = new ActorWorld(ppsUtility.getGrid())
        {
            //Private Variables
            private PredatorPreySystemUtility pps = ppsUtility;
            private int timeCounter = 0;

            @Override
            public void step() {

                pps.reset();
                pps.recountPrey();
                super.step();
                //Recounts Populations
                for (Location loc: getGrid().getOccupiedLocations())
                    if (getGrid().get(loc) instanceof Prey)
                        pps.incrementPreyPopulation();
                    else
                        pps.incrementPredatorPopulation();
                String output = "[PredatorPreySystems][" + timeCounter++ + "]PreyPopultation: "
                        + pps.getPreyPopulation() + " Prey[GvsD]:(" + pps.getPreyGrowth() + "," +
                        pps.getPreyDecay() + ") PredatorPopulation: " + pps.getPredatorPopulation()
                        + " Predator[GvsD]:(" + pps.getPredatorGrowth() + "," +
                        pps.getPredatorDecay() + ")";
                System.out.println(output);
                //Resets numbers and recounts prey for predator use
            }

        };
        //Adds about 4 times as many prey as predators in random locations
        for (int i = 0; i < GRID_SIZE * 4; i++)
            new Prey(0).putSelfInGrid(world.getGrid(), new Location((int)(Math.random() *
                    25), (int)(Math.random() * 25)));
        for (int i = 0; i < GRID_SIZE; i++)
            new Predator(8,3).putSelfInGrid(world.getGrid(), new Location((int)(Math.random() *
                    25), (int)(Math.random() * 25)));
//        new Predator(6,3).putSelfInGrid(world.getGrid(), new Location(0,0));
//        new Prey(3).putSelfInGrid(world.getGrid(), new Location(6,1));
//        new Prey(3).putSelfInGrid(world.getGrid(), new Location(0,8));
        world.show();
    }

    public static PredatorPreySystemUtility getPpsUtility() {
        return ppsUtility;
    }


}
